import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wjs.dao.CategoryMapper;
import com.wjs.dao.TeaMapper;
import com.wjs.dao.UsersMapper;
import com.wjs.entity.Category;
import com.wjs.entity.Tea;
import com.wjs.entity.User;
import com.wjs.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class test {
    @Test
    public void test1() {
        SqlSession session = null;
        try {
            session = MybatisUtils.getSession();
            System.out.println(session);
            UsersMapper um = session.getMapper(UsersMapper.class);
            User user2 = new User();
            user2.setId(10);
            user2.setUsername("小母牛");
            user2.setPassword("123456");
            User user = um.selectByNameAndPwd(user2);
            System.out.println(user2.toString());
            System.out.println(user.toString());


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSession(session);
        }
    }

    @Test
    public void test2() {
        SqlSession session = null;
        try {
            session = MybatisUtils.getSession();
            System.out.println(session);
            CategoryMapper cm = session.getMapper(CategoryMapper.class);
            cm.selectAll().forEach(System.out::println);
            Date date=new Date();//此时date为当前的时间

            SimpleDateFormat dateFormat=new SimpleDateFormat("YYYY-MM-dd");//设置当前时间的格式，为年-月-日
            System.out.println(dateFormat.format(date));

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSession(session);
        }
    }
    @Test
    public void test3() {
        SqlSession session = null;
        try {
            //获取查询全部的list集合
            session = MybatisUtils.getSession();
            TeaMapper tm=session.getMapper(TeaMapper.class);


            //设置分页信息。第一个参数是页号，第二个参数是一页显示的条数
            PageHelper.startPage(1, 3);
            //获取集合
            List<Tea> teaList=tm.selectAll();
            //将集合封装进PageInfo
            PageInfo pi=new PageInfo(teaList);
            System.out.println(pi);
            //pi.forEach(System.out::println);


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSession(session);
        }
    }

    @Test
    public void test4() {
        SqlSession session = null;
        try {
            //获取查询全部的list集合
            session = MybatisUtils.getSession();
            CategoryMapper cm=session.getMapper(CategoryMapper.class);
            List<Category> list= cm.selectAll();
            list.forEach(System.out::println);





        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSession(session);
        }
    }

    @Test
    public void test5() {
        SqlSession session = null;
        try {
            //获取查询全部的list集合
            session = MybatisUtils.getSession();
            CategoryMapper cm=session.getMapper(CategoryMapper.class);


            //设置分页信息。第一个参数是页号，第二个参数是一页显示的条数
            PageHelper.startPage(1, 2);
            //获取集合
            List<Category> teaList=cm.selectAll();
            //将集合封装进PageInfo
            PageInfo pi=new PageInfo(teaList);
            System.out.println(pi);
            //pi.forEach(System.out::println);


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MybatisUtils.closeSession(session);
        }
    }
}
